
import {articleCategoryList,list} from "../../../../api/article"
import {
  getInfo
} from '../../../../api/mch'
let app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },
  lifetimes: {
    attached: function() {
      this.setNavSize()
      this.loadMch()
      // 在组件实例进入页面节点树时执行
      this.articleCategoryListfuntion()
      this.activelist()
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    articleCategorys:[],
    tabCur:"",
    isChose:0,
    info:[],
    pageNum: 1,
    pageSize: 20,
    productType:false
    // scrollLeft: (e.currentTarget.dataset.id - 2) * 200
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // downRefresh(){
    //   console.log("这是视频组件");
    //   this.articleCategoryListfuntion()
    //   this.activelist()
    // },
    searchClick() {
      wx.navigateTo({
        url: '/pages/goods/search/index'
      })
    },
    foundClick(e) {
      console.log('8888');
      console.log(e);
      wx.navigateTo({
        url: '/pages/videocontentdeail/videocontentdeail?id=' + e.currentTarget.dataset.id+'&productId='+ e.currentTarget.dataset.productid,
      })
    },
    loadMch() {
      var _this = this;
      getInfo(app.globalData.mchId).then(res => {
        _this.data.mch = res.data;
        _this.setData({
          mch:_this.data.mch
        })
      });
    },
    setNavSize: function() {
      var that = this,
        sysinfo = wx.getSystemInfoSync(),
        statusHeight = sysinfo.statusBarHeight,
        isiOS = sysinfo.system.indexOf('iOS') > -1,
        navHeight;
      console.log(sysinfo)
      if (!isiOS) {
        navHeight = 48;
      } else {
        navHeight = 44;
      }
      that.setData({
        status: statusHeight,
        navHeight: navHeight
      })
    },
    activelist(){
 
      list({
        pageNum:this.data.pageNum,
        pageSize:this.data.pageSize,
        articleCategoryId:this.data.tabCur
      }).then(res=>{
        res.data.data.forEach(item => {
          this.data.info.push(item)
        });
        if(res.data.data.length<20){
          this.data.productType=true
        }
          this.setData({
            info:this.data.info,
            productType:this.data.productType
          })
     
      })
 
    },
    tabSelect(e) {
      this.data.pageNum=1
      this.data.info=[]
      this.setData({
        tabCur: e.currentTarget.dataset.id,
        isChose:e.currentTarget.dataset.index,
        scrollLeft: (e.currentTarget.dataset.id - 2) * 200
      })
      this.activelist()
    },
  
    articleCategoryListfuntion(){
      articleCategoryList().then(res=>{
        console.log('这是文章分类');
        console.log(res);
        res.data.unshift({
          name:'全部',
          id:'',
      })
        this.data.articleCategorys=res.data
        // this.articleCategory=res.data.filter(item=>{
        //   return item.name
        // })
        this.setData({
          articleCategorys:this.data.articleCategorys
        })
      })
    },
    onReachBottom(){
      console.log('555555555555555');
      this.data.pageNum++
      this.activelist()
    }
    // onReachBottom: function (callback) {
    //   this.activelist(() => {
    //     if (callback) {
    //       callback()
    //     }
    //   })

    // },
  
  }
})
